package cc.idoone.locale;

import org.springframework.web.servlet.i18n.AcceptHeaderLocaleResolver;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Locale;

/**
 * 基于URL请求的国际化的实现
 */
public class MyAcceptHeaderLocaleResolver extends AcceptHeaderLocaleResolver {

    private ThreadLocal<Locale> myLocal = new ThreadLocal<>();

    public Locale resolveLocale(HttpServletRequest request) {
        if (myLocal.get() == null) {
            myLocal.set(Locale.CHINA);
        }
        System.out.println("resolveLocale: " + Thread.currentThread().getId());
        return myLocal.get();
    }

    public void setLocale(HttpServletRequest request, HttpServletResponse response, Locale locale) {
        myLocal.set(locale);
        System.out.println("setLocale: " + Thread.currentThread().getId());
    }

}
